/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) [2019] [Fudan Microelectronics]
  * THIS SOFTWARE is licensed under the Mulan PSL v1.
  * can use this software according to the terms and conditions of the Mulan PSL v1.
  * You may obtain a copy of Mulan PSL v1 at:
  * http://license.coscl.org.cn/MulanPSL
  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
  * PURPOSE.
  * See the Mulan PSL v1 for more details.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sys_user.h"

#if defined(USE_FULL_ASSERT)
#include "fm33_assert.h"
#endif /* USE_FULL_ASSERT */

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

typedef struct {
    union {
        uint8_t value;
        struct {
            uint8_t light_left: 1;  // 左转向
            uint8_t light_right: 1; // 右转向
            uint8_t light_far: 1;   // 远光灯
            uint8_t light_near: 1;  // 近光灯
            uint8_t light_pos: 1;   // 位置灯
            uint8_t acc: 1;         // acc 状态
            uint8_t vcc2: 1;        // dc12v 电源
            uint8_t reserved: 1;    // 保留
        } raw;
    } io;

    union {
        uint8_t value;
        struct {
            uint8_t up: 1;
            uint8_t down: 1;
            uint8_t reserved: 6;
        };
    } key;

    uint16_t reserved_1: 1;
    uint16_t k_line_valid: 1;       // k线是否有数据
    uint16_t reserved: 14;          // 保留
    uint16_t light_value;          // 光感电压, 0 ~ 3300mv
    uint16_t bat_small_value;      // 小电池电压，0 ~ 15000mV
    struct {
        uint32_t hour: 8;
        uint32_t minute: 8;
        uint32_t second: 8;
        uint32_t reserved: 8;
        /* data */
    } __attribute__ ((packed)) time;
    uint32_t reserved_2;
} __attribute__ ((packed)) mcu_status_t;

typedef struct {
    uint32_t headlights_enable: 1;   // 光感大灯是否开启
    uint32_t reserved: 31;
} __attribute__ ((packed)) motorcycle_info_t;

typedef struct {
    union {
        struct {
            uint32_t b: 8;
            uint32_t g: 8;
            uint32_t r: 8;
            uint32_t reserved: 8;
        };
        uint32_t value;
    };
} __attribute__ ((packed)) color_info_t;

typedef struct {
    uint8_t hour: 8;           // 时间小时
    uint8_t minue : 8;         // 时间分钟
    uint8_t second: 8;         // 时间秒钟
    uint8_t reserved: 8;
} __attribute__ ((packed)) rtc_time_t;

// FM33回复ESP32消息
typedef struct {
    uint16_t error_code: 7;
    uint16_t in_boot: 1;
    uint16_t reserve: 8;
    uint16_t mask;
    /* data */
} __attribute__ ((packed)) cmd_rsp_t;

enum {
    // boot cmd
    CMD_WRITE_FLASH = 0x000a,
    CMD_OTA_FINISH = 0x000b,
    CMD_INQUIRY_VERSION = 0x000c,
    CMD_HOLD_BOOT = 0x000d,             // BOOT页面时间保持时间设置为1s
    CMD_EXIT_BOOT = 0x000e,             // 退出BOOT页面

    // app cmd
    CMD_K_MSG_TO_ESP32 = 0x0011,        // K线消息上报到ESP32
    CMD_ESP32_TO_K_MSG = 0x0012,        // ESP32下发K线消息
    
    CMD_RESET = 0x0019,                 // FM33复位
    CMD_STATUS_TO_ESP32 = 0x001a,       // 消息上报到ESP32
    CMD_STATUS_TO_FM33 = 0x001b,        // 下发消息到FM33
    CMD_SEND_COLOR_TO_FM33 = 0x001c,    // 下发颜色到FM33
    CMD_SEND_TIME_TO_FM33 = 0x001e,     // 下发时间到FM33
};

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */

/************************ (C) COPYRIGHT FMSH *****END OF FILE****/
